cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(recipe-05 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_library(leaky_implementation leaky_implementation.cpp)

add_executable(cpp_test test.cpp)
target_link_libraries(cpp_test
        PRIVATE leaky_implementation
)

find_program(MEMCHECK_COMMAND NAMES valgrind)                                   # 定义一个变量名字MEMCHECK_COMMAND代表valgrind
set(MEMCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full")          # 给valgrind添加命令参数
message(STATUS "MEMCHECK_COMMAD: ${MEMCHECK_COMMAND}")
message(STATUS "MEMCHECK_COMMAND_OPTIONS: ${MEMCHECK_COMMAND_OPTIONS}")

include(CTest)                                                                  # 要显示包含，不然无法运行ctest -T memcheck
enable_testing()
add_test(
        NAME cpp_test
        COMMAND $<TARGET_FILE:cpp_test>
)